package com.tentact.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.annotation.JsonCreator.Mode;
import com.tentact.service.MeetingRoomService;
import com.tentact.vo.Meetingroom;

@Controller
public class MeetingRoomController {
	@Autowired
	private MeetingRoomService service;
	
	//添加会议室
	@RequestMapping("/insertMeetingRoom")
	public String insertMeetingRoom(Meetingroom room) {
		service.insertSelective(room);
		return "redirect:selectMeetingRoom";
	}
	//查看所有会议室
	@RequestMapping("/selectMeetingRoom")
	public String selectMeetingRoom(Model model) {
		List<Meetingroom> rooms = service.selectAll();
		model.addAttribute("rooms", rooms);
		return "meetingrooms";
	}
	//查询会议室详情
	@RequestMapping("/selectRoomByRoomid")
	public String selectRoomByRoomid(Integer roomid,Model model) {
		Meetingroom room=service.selectByPrimaryKey(roomid);
		model.addAttribute("room", room);
		return "roomdetails";
	}
	//修改会议室
	@RequestMapping("/updateMeetingRoom")
	public String updateMeetingRoom(Meetingroom room) {
		service.updateByPrimaryKeySelective(room);
		return "redirect:selectMeetingRoom";
	}
	
	//查询预定会议室
	@RequestMapping("/selectOrderRoom")
	@ResponseBody
	public List<Meetingroom> selectOrderRoom(Integer roomcapacity,@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")Date begintime, 
			@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")Date endtime) {
		List<Meetingroom> rooms = service.selectOrderingRoom(roomcapacity,begintime,endtime);
		return rooms;
	}

}
